# common.py
from __future__ import with_statement

import sys
import logging
import os

def setup_logging():
    directory = '' if sys.platform == 'win32' else './'
    filename = directory+sys.argv[0]+'.log'
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(levelname)s %(message)s',
                        filename=filename)
    logging.debug('Start '+sys.argv[0]+' pid '+str(os.getpid()))
    # with open(sys.argv[0]+'.pid.'+str(os.getpid()),'w') as f:
    #     f.write('foobar')

def to_amps(circuit, count):
    if circuit < 3:
        return 0 if count == '0' else 0.0289 * int(count,16) + 0.03565
    else:
        return 0 if count == '0' else 0.0043 * int(count,16) + 0.0287



